<?php
	/*

	   Página que lista os objetos de uma categoria do Banco de Experiências separados por subCategoria.
	   Isso no ambiente do aluno, dentro do curso.

	*/

	session_start();

	include("/var/www/html/vivencias/conexaoBD.php");

	$query     = "SELECT nome FROM categoriasBancoExperiencias WHERE idCategoria='".$_GET['idCategoria']."'";
	$resultado = mysql_query($query,$conexao);
	$objeto    = mysql_fetch_object($resultado);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Experi&ecirc;ncias do Processo de Adoecimento</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="vivencias.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
<!--

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//-->//-->
</script>
</head>

<body>
<div align="center">
  <table width="1000" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="10%" align="left" valign="top"><img src="imagens/logo.jpg" width="66" height="53"></td>
                  <td width="90%"><img src="imagens/tit1.jpg" width="612" height="28"></td>
                </tr>
              </table></td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr align="left" valign="middle">
                  <td colspan="3" class="nomecurso"><?php echo $_SESSION['nomeCurso']; ?></td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td><a href="index.php"><img src="imagens/sair.gif" width="33" height="19" border="0"></a></td>
                </tr>
                <tr align="left" valign="middle">
                  <td width="25%">&nbsp;</td>
                  <td width="22%">&nbsp;</td>
                  <td width="52%">&nbsp;</td>
                  <td width="0%">&nbsp;</td>
                  <td width="0%">&nbsp;</td>
                  <td width="1%">&nbsp;</td>
                </tr>
              </table></td>
          </tr>
          <tr>
            <td><table width="96%" border="0" cellspacing="0" cellpadding="0">
                <tr align="left" valign="top">
		<!-- Somente o professor pode visualizar o gerenciamento.-->
		<?php if(($_SESSION['idTipoUsuario']=="0")||($_SESSION['idTipoUsuario']=="1")||($_SESSION['idTipoUsuario']=="5")){?>
                  <td width="3%" background="imagens/bar_fnd_8.jpg" bgcolor="EBF4F9"><a href="relatorios.htm"><img src="imagens/mn_8.jpg" width="23" height="161" border="0"></a></td>
		<?php } ?>
                  <td width="3%" background="imagens/bar_fnd_7.jpg"><a href="info.php"><img src="imagens/mn_7.jpg" width="23" height="137" border="0"></a></td>
                  <td width="3%" background="imagens/bar_fnd_6.jpg"><a href="esppess.php"><img src="imagens/mn_6.jpg" width="23" height="156" border="0"></a></td>
                  <td width="3%" background="imagens/bar_fnd_5.jpg"><a href="comunicacao.php"><img src="imagens/mn_5.jpg" width="23" height="146" border="0"></a></td>
                  <td width="3%" background="imagens/bar_fnd_4.jpg"><a href="banco.php"><img src="imagens/mn_4.jpg" width="23" height="219" border="0"></a></td>
                  <td width="69%" align="center" bgcolor="F1FAFD">
                    <table width="816" border="0" cellpadding="0" cellspacing="0">
                      <tr align="left" valign="top">
                        <td width="10" height="21"><img src="imagens/pix_cor4b.gif" width="10" height="8"></td>
                        <td width="556" valign="middle"><a href="banco.php" class="azul">Voltar</a></td>
                      </tr>
                      <tr align="center" valign="middle">
                        <td colspan="2"><img src="imagens/pix_cor2d.gif" width="810" height="2"></td>
                      </tr>
                      <tr align="left" valign="top">
                        <td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                              <td width="2%"><img src="imagens/pix_cor4b.gif" width="10" height="8"></td>
                              <td width="9%">&nbsp;</td>
                              <td width="2%"><img src="imagens/pix_cor4b.gif" width="10" height="8"></td>
                              <td width="8%">&nbsp;</td>
                              <td width="2%"><img src="imagens/pix_cor4b.gif" width="10" height="8"></td>
                              <td width="7%">&nbsp;</td>
                              <td width="2%"><img src="imagens/pix_cor4b.gif" width="10" height="8"></td>
                              <td width="6%">&nbsp;</td>
                              <td><img src="imagens/pix_cor4b.gif" width="10" height="8"></td>
                            </tr>
                          </table></td>
                      </tr>
                    </table>
                    <table width="95%" border="0" cellpadding="5" cellspacing="1">
                      <tr>
                        <td align="left" valign="middle" class="ativo">&nbsp;</td>
                      </tr>
                      <tr>
                        <td align="left" valign="middle" bgcolor="cce4eb" class="ativo">
                          <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                            <tr align="center" bgcolor="79b7c9" class="ativo">
                              <td width="14%" align="left" valign="middle" bgcolor="79b7c9"><a href="pp.carol.htm" class="ativo"></a>Categoria
                              </td>
                              <td width="86%" align="left" valign="middle" bgcolor="79b7c9"><?php echo $objeto->nome; ?></td>
                            </tr>
                          </table></td>
                      </tr>

		     <?php

				$query1 	= "SELECT nome,idSubCategoria FROM subCategBancoExp WHERE idCategoria='".$_GET['idCategoria']."'";
				$resultado1 = mysql_query($query1,$conexao);
				while($objeto1 = mysql_fetch_object($resultado1)){

		    ?>


                      <tr>
                        <td align="left" valign="middle" bgcolor="cce4eb" class="ativo"><table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
                            <tr align="center" bgcolor="d8e4f5" class="texttab">
                              <td width="22%" align="left" valign="middle" bgcolor="b2d4de" class="ativomenor">Subcategoria
                              </td>
                              <td width="78%" align="left" valign="middle" bgcolor="b2d4de" class="ativomenor"><?php echo $objeto1->nome;?></td>
                            </tr>

		     <?php
		     
				//Selecionando as permissoes dos objetos daquele curso e seus dados
				$query2     = "SELECT objetosBancoExperiencias.permissoes,objetosBancoExperiencias.caminho,objetosBancoExperiencias.frase,objetosBancoExperiencias.comentario,objetosBancoExperiencias.tipo,objetosBancoExperiencias.idObjeto  FROM objetosBancoExperiencias,cursosObjetos,subCategBancoExp WHERE cursosObjetos.idCurso = '".$_SESSION['idCurso']."' AND cursosObjetos.idObjeto = objetosBancoExperiencias.idObjeto AND cursosObjetos.idSubCategoria = $objeto1->idSubCategoria AND cursosObjetos.idSubCategoria = subCategBancoExp.idSubCategoria";
				$resultado2 = mysql_query($query2,$conexao);
				
				while($objeto2 = mysql_fetch_object($resultado2)){//enqt ele retornar um objeto, verifica-se a permissao
					
					$tipoUsuario = explode(",",$objeto2->permissoes);//retorna um vetor onde cada posicao do vetor guarda o tipo do usuario que tem permissao pra ver aquele arquivo
					
					for($i = 0;$i < count($tipoUsuario);$i++){
						
						//Pega a id do dono do objeto
						$queryDonoObj     = "SELECT idUsuario FROM usuariosObjetos WHERE idObjeto=".$objeto2->idObjeto." AND dono=1";
						$resultadoDonoObj = mysql_query($queryDonoObj, $conexao);
						$objetoDono       = mysql_fetch_object($resultadoDonoObj);
						$idDono           = $objetoDono->idUsuario;
						
						//se o tipo de usuario que tem permissao pra visualizar o objeto for igual ao tipo do usuario que tah logado ou o usuario que inseriu o objeto ou o administrador
						if( ($tipoUsuario[$i] == $_SESSION['idTipoUsuario']) || ($_SESSION['idUsuario'] == $idDono) || ($_SESSION['idTipoUsuario'] == 5)){

		     ?>


                            <tr align="center" bgcolor="cce4eb" class="texttab">
                              <td align="left" valign="middle" class="ativomenor"><strong><a href="javascript:void(0)" class="texto2" onClick='MM_openBrWindow("detalhes1b.htm", "Janela", "toolbar=0 scrollbars=yes width=600 height=700")' span>
                                </a></strong> <table width="98%" border="0" cellspacing="1" cellpadding="1">
                                  <tr align="center" valign="middle">
                                    <td><strong><a href="javascript:void(0)" class="texto2" onClick='MM_openBrWindow("detalhes2b.htm", "Janela", "toolbar=0 scrollbars=yes width=600 height=700")' span>
                                      </a>
				    	<?php if($objeto2->tipo==0){ ?>	<a href="<?php echo $objeto2->caminho;?>"><img src="imagens/bot.video.gif" alt="ver depoimento" width="26" height="26" border="0"></a></strong></td><?php } ?>
                                    <td><?php if($objeto2->tipo==1){?><a href="<?php echo $objeto2->caminho;?>"><img src="imagens/bot.som.gif" alt="ouvir depoimento" width="26" height="26" border="0"></a></td><?php } ?>
                                    <td><?php if($objeto2->tipo==2){?><a href="<?php echo $objeto2->caminho;?>"><img src="imagens/bot.papel.gif" alt="ler depoimento" width="26" height="26" border="0"></a></td><?php } ?>
 				    <td><?php if($objeto2->tipo==3){?><a href="<?php echo $objeto2->caminho;?>"><img src="imagens/bot.foto.gif" alt="ouvir depoimento" width="26" height="26" border="0"></a></td><?php } ?>
                                  </tr>
                                  <tr align="center" valign="middle">
                                    <td colspan="3"><strong><a href="javascript:void(0)" class="texto2" onClick='MM_openBrWindow("detalhes2b.htm", "Janela", "toolbar=0 scrollbars=yes width=600 height=700")' span>
                                      </a><a href="javascript:void(0)" class="texto2" onClick="javascript:window.open('detalhesObjetoBancoExpUsuario.php?idObjeto=<?php echo $objeto2->idObjeto;?>','Janela','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=600,height=700');" span>
                                      <input type="submit" name="Submit2343" value="Detalhes">
                                      </a><a href="javascript:void(0)" class="texto2" onClick='MM_openBrWindow("detalhes2b.htm", "Janela", "toolbar=0 scrollbars=yes width=600 height=700")' span>
                                      </a></strong></td>
                                  </tr>
                                </table></td>
                              <td align="left" valign="middle" bgcolor="cce4eb" class="ativomenor"><span><a href="<?php echo $objeto2->caminho;?>" class="miudo">Depoimento
                                <?php $count = $count + 1; echo $count; ?></a></span><strong><br>
                                </strong> <span class="texto2"><strong><?php echo $objeto2->comentario;?></strong></span><strong><br>
                                </strong><a href="<?php echo $objeto2->caminho;?>" class="texto2"><?php echo $objeto2->frase;?></a></td>
                            </tr><?php $i = count($tipoUsuario);}}}?><!--fechando o if e o for e o while -->
                          </table></td>
                      </tr>
		     <?php } ?><!--fechando o outro while -->
                    </table>
                    <p><br>
                    </p>
                    <p><strong><a href="javascript:void(0)" target="Inserir conteudo" class="texto2" onClick='MM_openBrWindow("detalhes1b.htm", "Janela", "toolbar=0 scrollbars=yes width=600 height=700")' span>
                      </a></strong> </p></td>
                  <td width="5%" align="right" background="imagens/bar_fnd_3.jpg"><a href="ferramentasTrabalho.php"><img src="imagens/mn_3.jpg" width="23" height="249" border="0"></a>
                  </td>
                  <td width="3%" align="right" background="imagens/bar_fnd_2.jpg"><a href="conteudo.php"><img src="imagens/mn_2.jpg" width="23" height="113" border="0"></a></td>
                  <td width="8%" align="right" background="imagens/bar_fnd_1.jpg" bgcolor="F1FEF9">
                    <p><a href="principal.php"><img src="imagens/mn_1.jpg" width="23" height="103" border="0"></a></p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p>
                    <p>&nbsp;</p></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>
</body>
</html>
